cmake_minimum_required(VERSION 3.8)
project(zoros)

set(PLATFORM "x86_64")
# 你也可以组合这些判断条件
if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
    set(PLATFORM "aarch64")
endif ()

if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
    add_compile_options(-Wall -Wextra -Wpedantic)
endif ()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)
# ========== 生成自定义消息 ==========
rosidl_generate_interfaces(
        ${PROJECT_NAME}
        "msg/PlannerProperties.msg"
        "msg/ControllerMitProperties.msg"
        DEPENDENCIES std_msgs
#        LANGUAGES cpp python  # 明确告诉 ROS2 同时生成 C++ 和 Python 消息
)
# 导出 runtime 接口依赖（给别的包用）
ament_export_dependencies(rosidl_default_runtime)

include_directories(${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_cpp)

if (BUILD_TESTING)
    find_package(ament_lint_auto REQUIRED)
    # the following line skips the linter which checks for copyrights
    # comment the line when a copyright and license is added to all source files
    set(ament_cmake_copyright_FOUND TRUE)
    # the following line skips cpplint (only works in a git repo)
    # comment the line when this package is in a git repo and when
    # a copyright and license is added to all source files
    set(ament_cmake_cpplint_FOUND TRUE)
    ament_lint_auto_find_test_dependencies()
endif ()


###########
## Build ##
###########

## Specify additional locations of header files
## Your package locations should be listed before other locations

# 查找 src 目录下所有 .cpp 文件
file(GLOB SRC_FILES src/*.cpp)

# 添加可执行文件，包含 main.cpp 和所有 src 下的 .cpp 文件
add_executable(robot_manager_node
        main.cpp
        ${SRC_FILES})

target_include_directories(robot_manager_node PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
        $<INSTALL_INTERFACE:include>
        include/robot_manager/
        /opt/zoral/${PLATFORM}/include
        /opt/zoral/${PLATFORM}/include/third_party
)

target_link_directories(robot_manager_node PUBLIC
  /opt/zoral/${PLATFORM}/lib
)

# 获取目标的 typesupport 依赖
rosidl_get_typesupport_target(cpp_typesupport_target ${PROJECT_NAME}
        rosidl_typesupport_cpp)

target_link_libraries(robot_manager_node
        zoral
        ${cpp_typesupport_target}
)

ament_target_dependencies(robot_manager_node
        rclcpp
        std_msgs
        sensor_msgs
)

install(TARGETS robot_manager_node
        DESTINATION lib/${PROJECT_NAME}
)

install(
        DIRECTORY launch
        DESTINATION share/${PROJECT_NAME}/
)

# Install Python GUI scripts
install(PROGRAMS
        zoros_gui/joint_control_gui.py
        DESTINATION lib/${PROJECT_NAME}
)

ament_package()